package com.itheima.api.pms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.pms.PmsBrandMapper;
import com.itheima.vo.domain.TableDataInfo;
import com.itheima.vo.pojo.PmsBrand;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;


@DubboService  //注册中心
public class PmsBrandServiceImpl   extends ServiceImpl<PmsBrandMapper, PmsBrand> implements PmsBrandService {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    @Override
    public TableDataInfo queryPage(Integer pageNum, Integer pageSize, String keyword) {
        Page<PmsBrand> page = new Page<>(pageNum,pageSize);
        TableDataInfo tableDataInfo = new TableDataInfo();
        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(keyword),PmsBrand::getName,keyword);
        pmsBrandMapper.selectPage(page,queryWrapper);
        tableDataInfo.setList(page.getRecords());
        tableDataInfo.setPageNum(pageNum);
        tableDataInfo.setPageSize(pageSize);
        tableDataInfo.setTotal(page.getTotal());
        tableDataInfo.setTotalPage(page.getPages());
        return tableDataInfo;
    }
}
